/*
 * 
 *  This file is part of Sourceprojects.org Lycia Copyright 2010 noctarius
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 */
package org.sourceprojects.lycia.internal;

/**
 * Internal interface for Caches to implement a set of standard caches due to
 * different situations.
 * 
 * @author noctarius
 * @since 1.9.1
 */
public interface Cache<T> {
	/**
	 * Get the standard time to live.
	 * 
	 * @return standard time to live
	 */
	long getExpire();

	/**
	 * Puts an element in the cache with standard time to live.
	 * 
	 * @param name
	 *            Key to save as
	 * @param obj
	 *            Value to save
	 */
	void put(final String name, final T obj);

	/**
	 * Puts an element in the cache with given time to expire.
	 * 
	 * @param name
	 *            Key to save as
	 * @param obj
	 *            Value to save
	 * @param expireTime
	 *            Time to live
	 */
	void put(final String name, final T obj, final long expireTime);

	/**
	 * Returns value to the given named key. Returns null if value is not cached
	 * yet or was removed by internal behavior.
	 * 
	 * @param name
	 *            Key to retrieve
	 * @return Cached value
	 */
	T get(final String name);

	/**
	 * Returns value to the given named key. Returns null if value is not cached
	 * yet or was removed by internal behavior. A special type
	 * 
	 * <pre>
	 * <R extends T>
	 * </pre>
	 * 
	 * can be given to convert the value to.
	 * 
	 * @param <R>
	 *            Type to convert to on get
	 * @param name
	 *            Key to retrieve
	 * @param type
	 *            Type to convert value to
	 * @return Cached value
	 */
	<R extends T> R get(final String name, final Class<R> type);

	/**
	 * Stops the actual cache and forces an internal cleanup if something needs
	 * to be done
	 */
	void shutdown();

	/**
	 * Invalidates all actually cached values
	 */
	void invalidate();
}
